<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>注册页</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">

  <link rel="stylesheet" href="/layui/css/layui.css">

<style>
body{padding: 10px;}
</style>
</head>
<body	class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-body">
    <form class="layui-form layui-form-pane1"	id="form" lay-filter="first">
  <div class="layui-form-item">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-inline">
      <input type="text" name="userName" lay-verify="required|userName" required placeholder="请输入用户名" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请务必填写用户名</div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">手机</label>
    <div class="layui-input-inline">
      <input type="tel" name="mobile" lay-verify="required|mobile" lay-verType="tips" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">邮箱</label>
    <div class="layui-input-inline">
      <input type="email" name="email" lay-verify="email"  lay-verType="alert" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
      <input type="password" name="password" lay-verify="required|pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
    </div>
    
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn"	id="send" lay-submit lay-filter="*">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
    </div>
  </div>


<br><br><br>


<script src="/layui/layui.js"></script>
<script src="/layui/jquery-2.1.4.js"></script>

<script>
layui.use('form', function(){
  var form = layui.form;
  
  //自定义验证规则
  form.verify({
	  userName: function(value){
      if(value.length < 3){
        return '用户名也太短了吧';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
    ,mobile: [
    	/(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/
      ,'请输入正确的手机号'
    ]
  });
  
  //监听提交
  form.on('submit(*)', function(data){
    
	  console.log(JSON.stringify(data.field));
    return false;
  });
  
});
$('#send').click(function() {
	console.log($("#form").serialize());
	$.ajax({
		type: "POST", //GET或POST,
		async:true, //默认设置为true，所有请求均为异步请求。
		url: "/js/petusers/register",
		data: $("#form").serialize(),
		dataType: "json", //xml、html、script、jsonp、text
		success: function(data) {
			if(data.res=='200'){
				window.location.href="/customer/"+data.petUserId+"/index"
			}
		},
		error:function(){},
	});
});
</script>


<script>
layui.use('jquery', function(){
  var $ = layui.jquery;
  var submit = function(){
    return false;
  };
  $('#test').on('submit', function(){
     return false
  });
  $('#test').on('submit', function(){
     return true
  });
});
</script>
</body>
</html>
